package com.infolab.aims.domain.purchase;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.joda.time.LocalDate;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import com.infolab.aims.GlobalConstant;
import com.infolab.aims.common.SpecialMuLineToStringStyle;
import com.infolab.aims.common.bean.AbstractModelBean;
import com.infolab.aims.domain.asset.AssetModel;

@Entity
@Table(name="AMTB_PURCHASEORDER_DETAIL")
public class PurchaseOrderDetail extends AbstractModelBean  {
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer purchaseOrderDetailId;
	
	@ManyToOne
	@JoinColumn(name="purcaseOrderId")
	private PurchaseOrder purchaseOrder;
	
	@ManyToOne
	@JoinColumn(name="assetModelId")
	private AssetModel assetModel;
	
	private Float unitPrice;
	
	private Integer quantityOrder;
	
	private Integer quantityReceived;
	
	@Transient
	private Integer quantityReceiving;
	
	public Integer getQuantityReceiving() {
		return quantityReceiving;
	}

	public void setQuantityReceiving(Integer quantityReceiving) {
		this.quantityReceiving = quantityReceiving;
	}

	private String purchaseOrderRemarks;
	
	@NotNull(message="{error.empty}")
	private Date etaDate;

	@Transient
	private boolean deleted;
	
	
	public String getAuditContentHead()
	{
		AssetModel model = assetModel;
		if(assetModel==null){
			model = new AssetModel();
		}
		return new ToStringBuilder(this,SpecialMuLineToStringStyle.SPECIAL_MULINE_STYLE)
			.append("Asset Model", model.getAssetModelCode() + " " + model.getAssetModelName())
			.append("Unit Price",unitPrice)
			.append("Quantity Order",quantityOrder)
			.append("Quantity Received", quantityReceived)
			.toString();
	}

	public Integer getPurchaseOrderDetailId() {
		return purchaseOrderDetailId;
	}

	public void setPurchaseOrderDetailId(Integer purchaseOrderDetailId) {
		this.purchaseOrderDetailId = purchaseOrderDetailId;
	}

	public PurchaseOrder getPurchaseOrder() {
		return purchaseOrder;
	}

	public void setPurchaseOrder(PurchaseOrder purchaseOrder) {
		this.purchaseOrder = purchaseOrder;
	}

	public AssetModel getAssetModel() {
		return assetModel;
	}

	public void setAssetModel(AssetModel assetModel) {
		this.assetModel = assetModel;
	}

	public Float getUnitPrice() {
		return unitPrice;
	}

	public void setUnitPrice(Float unitPrice) {
		this.unitPrice = unitPrice;
	}

	public Integer getQuantityOrder() {
		return quantityOrder;
	}

	public void setQuantityOrder(Integer quantityOrder) {
		this.quantityOrder = quantityOrder;
	}

	public Integer getQuantityReceived() {
		return quantityReceived;
	}

	public void setQuantityReceived(Integer quantityReceived) {
		this.quantityReceived = quantityReceived;
	}

	public String getPurchaseOrderRemarks() {
		return purchaseOrderRemarks;
	}

	public void setPurchaseOrderRemarks(String purchaseOrderRemarks) {
		this.purchaseOrderRemarks = purchaseOrderRemarks;
	}

	public Date getEtaDate() {
		return etaDate;
	}
	
	
	public String getEtaDateToDisplay()
	{
		DateTimeFormatter fmt = DateTimeFormat.forPattern(GlobalConstant.DATE_FORMAT_JAVA);
		
		if(etaDate!=null) return new LocalDate(etaDate.getTime()).toString(fmt);
				
		return "";
	}

	public void setEtaDate(Date etaDate) {
		this.etaDate = etaDate;
	}

	public boolean isDeleted() {
		return deleted;
	}

	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}
	
	
	
}
